/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;

/**
 *
 * @author Tomas
 */
@Entity
@Table(name = "ACCOUNT_HEADER")
public class AccountHeader implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue
    private Long id;
    
    @Column(name = "NAME")
    private String name;
    
    @Column(name = "CREATED_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date createdDate;
    
    @Column(name = "LAST_CHANGE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date lastChange;
    
    @Version
    @Column(name = "VERSION")
    private int version;
    
    @Column(name=  "DOWNLOAD_SHARED")    
    private int downloadShared = 0;
    
    @JoinColumn(name = "ROOT_FOLDER_ID", referencedColumnName = "ID")
    @OneToOne(optional = false)
    private Folder rootFolder;
    
    @JoinColumn(name = "OWNER_USER_ID", referencedColumnName = "ID")
    @ManyToOne(optional = false)
    private User ownerUser;
    
    public AccountHeader() {
    }

    public AccountHeader(Long id) {
        this.id = id;
    }

    public AccountHeader(Long id, String name, Date createdDate, int version) {
        this.id = id;
        this.name = name;
        this.createdDate = createdDate;
        this.version = version;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Date getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }

    public Date getLastChange() {
        return lastChange;
    }

    public void setLastChange(Date lastChange) {
        this.lastChange = lastChange;
    }

    public int getVersion() {
        return version;
    }

    public void setVersion(int version) {
        this.version = version;
    }

    public Folder getRootFolder() {
        return rootFolder;
    }

    public void setRootFolder(Folder rootFolderId) {
        this.rootFolder = rootFolderId;
    }

    public User getOwnerUser() {
        return ownerUser;
    }

    public void setOwnerUser(User ownerUserId) {
        this.ownerUser = ownerUserId;
    }

    public int getDownloadShared() {
        return downloadShared;
    }

    public void setDownloadShared(int downloadShared) {
        this.downloadShared = downloadShared;
    }
    
    public boolean isDownloadShared(){
        return downloadShared > 0;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof AccountHeader)) {
            return false;
        }
        AccountHeader other = (AccountHeader) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.AccountHeader[ id=" + id + " ]";
    }
    
}
